package com.qinhailin.web;



import com.itextpdf.text.log.SysoCounter;
import com.itextpdf.text.log.SysoLogger;
import com.jfinal.kit.Ret;
import com.jfinal.upload.UploadFile;
import com.qinhailin.common.base.BaseController;
import com.qinhailin.common.config.WebContant;
import com.qinhailin.common.routes.ControllerBind;
import com.qinhailin.common.util.Cmd;

import java.io.*;
import java.util.List;


@ControllerBind(path="/web/apkpack")
public class apkpackController extends  BaseController{

    public void startPack(){
        // 替代 getPara 的 get 用法
        String apkname = get("apkname");
        File kk=   new File("temp");

        String requestip=getRequest().getRemoteAddr();
        System.out.println("远程ip："+getRequest().getRemoteAddr());
       // getRequest().getRemotePort();

        Process p;
        String cmds = "cmd.exe copy -f "+WebContant.uploadFilepath + File.separator + "20102015"+ File.separator +"20102015051700004.apk "
                +WebContant.apktoolWorksspace + File.separator + "20102015"+ File.separator +"20102015051700004.apk "
                ;

        File targetfile = new File(WebContant.apktoolWorksspace + File.separator + requestip);
        if (targetfile.exists()){
            //文件存在
        }else {
            //文件不存在
            //1.根据ip创建文件夹
            String cmdmkdir = "cmd.exe /c mkdir "+WebContant.apktoolWorksspace + File.separator + requestip;

            Cmd.execCommand(cmdmkdir,WebContant.apktoolWorksspace);
        }



            //2.复制文件到创建的文件夹中
            String cmdcpfile = "cmd.exe cp "+WebContant.uploadFilepath + File.separator + "20102015"+ File.separator +"20102015051700004.apk "
                    +WebContant.apktoolWorksspace + File.separator + requestip + File.separator +"20102015051700004.apk ";

            Cmd.execCommand(cmdcpfile,WebContant.apktoolWorksspace);
            // 3. 改之理解压
            String cmdapktooldfile ="cmd.exe java -jar "+WebContant.apktoolWorksspace+File.separator+"apktool.jar d "+ WebContant.apktoolWorksspace + File.separator + requestip + File.separator +"20102015051700004.apk "
			+WebContant.apktoolWorksspace + File.separator + requestip + File.separator+"20102015051700004" ;
            Cmd.execCommand(cmdapktooldfile,WebContant.apktoolWorksspace);



        //System.out.println(cmds);
        //Cmd.execCommand(cmds);

        renderText("kaishi dabao "+apkname+".apk");
    }



}
